#include "zhuce.h"
#include "ui_zhuce.h"
#include <QDialog>
#include <QDebug>
#include <QMessageBox>
#include <QMovie>
#include <QStringList>
#include <QCompleter>
#include <QHBoxLayout>
#include <QIcon>
#include <QMouseEvent>
#include "widget.h"
#include <QSqlDatabase>
#include <QSqlQuery>

zhuce::zhuce(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::zhuce)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);
    setWindowIcon(QIcon("C:\\Users\\22509\\Pictures\\logo.jpg"));

    //label显示动态图片
    QMovie *movie=new QMovie();
    movie->setFileName("C:\\Users\\22509\\Pictures\\bg4.gif");
    ui->bg->setMovie(movie);
    movie->start();
    ui->bg->setScaledContents(true);//自适应

    //
    ui->lineEdit->setEchoMode(QLineEdit::Normal);
    ui->lineEdit_2->setEchoMode(QLineEdit::Password);
    ui->lineEdit_3->setEchoMode(QLineEdit::Password);

}

zhuce::~zhuce()
{
    delete ui;
}


void zhuce::mousePressEvent(QMouseEvent *event)
{
    m_lastPos = event->globalPos();
    isPressedWidget = true; // 当前鼠标按下的即是QWidget而非界面上布局的其它控件
}

void zhuce::mouseMoveEvent(QMouseEvent *event)
{
    if (isPressedWidget) {
        this->move(this->x() + (event->globalX() - m_lastPos.x()),
                   this->y() + (event->globalY() - m_lastPos.y()));
        m_lastPos = event->globalPos();
    }
}

void zhuce::mouseReleaseEvent(QMouseEvent *event)
{
    // 其实这里的mouseReleaseEvent函数可以不用重写
    m_lastPos = event->globalPos();
    isPressedWidget = false; // 鼠标松开时，置为false
}


void sqlite_Init();




void zhuce::on_Sure_clicked()
{
    sqlite_Init();
    QString username = ui->lineEdit->text();
    QString password = ui->lineEdit_2->text();
    QString surepass = ui->lineEdit_3->text();
    //判断密码是否一致
    if(username!=""&password!=""&surepass!="")
    {
        if(ui->lineEdit_2->text().length()>=5)
        {
            if(password == surepass)
            {
                QString sql=QString("insert into user(username,password) values('%1','%2');")
                        .arg(username).arg(password);
                //创建执行语句对象
                QSqlQuery query;
                //判断执行结果
                if(!query.exec(sql))
                {
                    qDebug()<<"insert into error";
                    QMessageBox::information(this,"注册认证","注册失败！");
                }
                else
                {
                    qDebug()<<"insert into success";
                    QMessageBox::information(this,"注册认证","注册成功！");
                }
            }
            else
            {
                QMessageBox::information(this,"注册认证","两次密码输入不一致！");
            }
        }
        else
        {
            QMessageBox::information(this,"注册认证","密码不能小于5位！");
        }

    }
    else
    {
        QMessageBox::information(this,"注册认证","信息不能为空！");
    }

}
